package org.leon.framework;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

public class MappedHost {

    private Map<String, Context> contextMap = new HashMap<>();

    private String hostName;
    private String appBase;

    public MappedHost(String hostName, String appBase) {
        this.hostName = hostName;
        this.appBase = appBase;
    }


    public void init() throws Exception {
        File dir = new File(this.appBase);
        if (dir.isDirectory()) {
            String[] subDir = dir.list();
            for (String sd : subDir) {
                File sdFile = new File(this.appBase + File.separator +sd);
                if (sdFile.isDirectory()) {
                    Context context = new Context(sd, this.appBase);
                    context.init();
                    contextMap.put(sd, context);
                }
            }
        }

    }

    public Context getContext(String contextName) {
        return contextMap.get(contextName);
    }

    public void setAppBase(String appBase) {
        this.appBase = appBase;
    }
}
